#pragma once

#include "../umlmodel_global.h"

#include <memory>
#include <vector>

#include "Association.h"
#include "Classifier.h"

using std::make_shared;
using std::shared_ptr;
using std::vector;

namespace uml {
class Class;
class ExtensionEnd;
class Property;

/// <summary>
/// Extension
/// An extension is used to indicate that the properties of a metaclass are extended
/// through a stereotype, and gives the ability to flexibly add (and later remove)
/// stereotypes to classes.
/// </summary>
class UMLMODEL_EXPORT Extension : public Classifier, public Association {

public: // Constructors and destructors
    explicit Extension(const QString& umlType="uml::Extension");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Methods
    /// <summary>
    /// metaclassEnd
    /// The query metaclassEnd() returns the Property that is typed by a metaclass (as
    /// opposed to a stereotype).
    /// </summary>
    virtual shared_ptr<Property> metaclassEnd() const;

public: // Properties
    /// <summary>
    /// isRequired getter
    /// Indicates whether an instance of the extending stereotype must be created when
    /// an instance of the extended class is created. The attribute value is derived
    /// from the value of the lower property of the ExtensionEnd referenced by
    /// Extension::ownedEnd; a lower value of 1 means that isRequired is true, but
    /// otherwise it is false. Since the default value of ExtensionEnd::lower is 0, the
    /// default value of isRequired is false.
    /// </summary>
    bool isRequired() const;

    /// <summary>
    /// isRequired setter
    /// Indicates whether an instance of the extending stereotype must be created when
    /// an instance of the extended class is created. The attribute value is derived
    /// from the value of the lower property of the ExtensionEnd referenced by
    /// Extension::ownedEnd; a lower value of 1 means that isRequired is true, but
    /// otherwise it is false. Since the default value of ExtensionEnd::lower is 0, the
    /// default value of isRequired is false.
    /// </summary>
    void setIsRequired(bool value);

    /// <summary>
    /// metaclass getter
    /// References the Class that is extended through an Extension. The property is
    /// derived from the type of the memberEnd that is not the ownedEnd.
    /// </summary>
    shared_ptr<Class> metaclass() const;

    /// <summary>
    /// metaclass setter
    /// References the Class that is extended through an Extension. The property is
    /// derived from the type of the memberEnd that is not the ownedEnd.
    /// </summary>
    void setMetaclass(shared_ptr<Class> value);

    /// <summary>
    /// ownedEnd getter
    /// References the end of the extension that is typed by a Stereotype.
    /// </summary>
    shared_ptr<ExtensionEnd> ownedEnd() const;

    /// <summary>
    /// ownedEnd setter
    /// References the end of the extension that is typed by a Stereotype.
    /// </summary>
    void setOwnedEnd(shared_ptr<ExtensionEnd> value);

private: // Fields
    /// <summary>
    /// isRequired
    /// Indicates whether an instance of the extending stereotype must be created when
    /// an instance of the extended class is created. The attribute value is derived
    /// from the value of the lower property of the ExtensionEnd referenced by
    /// Extension::ownedEnd; a lower value of 1 means that isRequired is true, but
    /// otherwise it is false. Since the default value of ExtensionEnd::lower is 0, the
    /// default value of isRequired is false.
    /// </summary>
    const static bool isRequired_default_;
    bool isRequired_= isRequired_default_;

    /// <summary>
    /// metaclass
    /// References the Class that is extended through an Extension. The property is
    /// derived from the type of the memberEnd that is not the ownedEnd.
    /// </summary>
    shared_ptr<Class> metaclass_;

    /// <summary>
    /// ownedEnd
    /// References the end of the extension that is typed by a Stereotype.
    /// </summary>
    shared_ptr<ExtensionEnd> ownedEnd_;

};

} // namespace uml
